import { PureComponent } from "react";
import { Button, Modal,ActivityIndicator,InputItem,TextareaItem,List } from "antd-mobile"
import { connect } from 'dva';
import { handleImg, goToPage,isNull } from "../../utils/helper";
import { Row, Col,Select,} from 'antd';
import MToast from '../../components/Util/MToast';
import {IntlProvider, addLocaleData,FormattedMessage} from 'react-intl';
import 'antd/dist/antd.css'; // or 'antd/dist/antd.less'
import localeData from '../../../public/lang/data.json';
@connect(() => {
  return ({

  })
})
export default class FeedBack extends PureComponent{
  constructor(props){
    super(props);
    this.state = {
      feedback:''
    }
  }
  componentWillMount(){
    let {dispatch,location} = this.props;
    dispatch({
      type: "global/setHeaderTitle",
      payload: {
        title: localeData[localStorage.locale].feedback,
        path: location.pathname + location.search
      }
    });

  }
  handleChange=(e)=>{
    this.setState({
      feedback:e
    })
    console.log(e)
  }
  feedClick=()=>{
    let {dispatch,location} = this.props;
    let {feedback} = this.state;
    if (isNull(feedback)) {
      MToast.fail(T(localeData[localStorage.locale].feedText), 3, null, false);
      return;
    }
    dispatch({
      type: "form/query",
      payload: {
        apiInfo: {
          url: "ent/create?_c=app_feed_back",
          params: [
            {
              key: "tell_us",
              value: feedback
            }
          ],
        },
        callback: (result) => {
          let { data } = result;
          MToast.info(T(localeData[localStorage.locale].feedSuccess,3, null, false));
          setTimeout(() => {
            if (browser.isInApp) {
              Func.callHander(bridge, "openHomePage", {})
            }
            // else{
            //   this.props.history.replace("/");
            //   window.location.reload();
            // }
            goToPage({ dispatch, config: { url: "/my" }, })
          }, 5000);


        }
      }
    });
  }
  render(){
    let {dispatch} = this.props;
    let {img,img1} = this.state;
    const messages = localeData[localStorage.locale];
    return(
      <IntlProvider
        locale={ localStorage.locale } messages={messages}
      >
        <div style={{height:"100%",position: 'relative',height:'100%',background:'#fff'}}>
          <div style={{paddingTop:'80px'}}>
            <List>
              <TextareaItem
                className="required"
                placeholder={messages.feedText}
                data-seed="logId"
                rows={3}
                autoHeight
                onChange={this.handleChange}
              />
            </List>



          </div>
          <Row style={{position:'fixed',bottom:'0px',width:'100%'}}>
            <Button  type="primary" size="default" style={{ margin: "0 auto 20px",width:'80%',background:'#F09600',borderRadius:'20px',border:'0px',height:'42px',lineHeight:'42px' }} onClick={this.feedClick}>{messages.placeOrderSelfConfirm}</Button>
          </Row>


        </div>
      </IntlProvider>
    )
  }
}
